package com.lenovo.util;
import java.security.MessageDigest;

public class Md5Util {
//	private static Log log = LogFactory.getLog(Md5Util.class);
	public static String MD5Encode(String sourceString) {
		String resultString = null;
		try {
			resultString = new String(sourceString);
			MessageDigest md = MessageDigest.getInstance("MD5");
			resultString = byte2hexString(md.digest(resultString.getBytes()));
		} catch (Exception ex) {
		}
		return resultString;
	}
	public static final String byte2hexString(byte[] bytes) {
		StringBuffer buf = new StringBuffer(bytes.length * 2);
		for (int i = 0; i < bytes.length; i++) {
			if (((int) bytes[i] & 0xff) < 0x10) {
				buf.append("0");
			}
			buf.append(Long.toString((int) bytes[i] & 0xff, 16));
		}
		return buf.toString();
	}
	public static void main(String[] args) throws Exception {
//		log.debug(MD5Encode("app_key=4dd7a69ed7de049c2f45c8d6a335e75bba_auth_mobile=13601203291target_user_id=265timestamp=1303898327905621b62abefa7f739647345fdf30fd97e"));
//		System.out.println(byte2hexString("5d41402abc4b2a76b9719d911017c592"));
///		System.out.println(byte2hexString("hello"));
//		log.debug(MD5Encode("123456"));
//		log.debug(MD5Encode("111111"));
	//	System.out.println(MD5Encode("xhns_user_list"));
		System.out.println(getGID("1234","4321"));
		System.out.println(getGID("4321","1234"));
	}
	
	/***
	 * 获取G_ID
	 * @param min_id
	 * @param max_id
	 * @return
	 */
  public static final String getGID(String  min_id ,String max_id ) throws Exception
  {
	  
	    long  min =Long.parseLong(min_id);
	    long  max =Long.parseLong(max_id);
	    long temp_long = 0l;
	   
	    if(max < min)
	    {
	    	temp_long =min;
	    	min =max;
	    	max =temp_long;
	    }
	  
	     String totalStr =(MD5Encode(min+"")+MD5Encode(max+"")).toLowerCase();
	     return MD5Encode(totalStr).toLowerCase();
  }
	
	
}
